package com.ruoyi.food.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//继承WebMvcConfigurer扩展mvc
//用于往容器中添加组件
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    //上传地址
    @Value("${upload.filepath}")
    private String filePath;

    //显示相对地址
    @Value("${file.upload.path.relative}")
    private String fileRelativePath;

    /**
     * 资源映射路径
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(fileRelativePath).addResourceLocations("file:/" + filePath);
    }
}

